package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service//阿里的
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        //执行
        userMapper.insert(user);

        //返回主键
        return user.getId();
    }

    @Override
    public User findByPhone(String phone) {
        //追加条件 where phone = #{phone}
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);

        //执行
        return userMapper.selectOne(wrapper);
    }

    //根据用户id查询用户信息（目的是为了获取用户信息）
    @Override
    public User findUserByUserId(Integer userId) {
        User user = userMapper.selectById(userId);
        return user;
    }
    //修改手机号
    @Override
    public void update(User user1) {
        userMapper.updateById(user1);
    }




}
